// const ws = new WebSocket("ws://localhost:8060");
const ws = new WebSocket("ws://106.55.48.147:8060");
import store from '../store/index'
let wsConnection = {
    initWebSocket() {

        ws.addEventListener("open", this.handleWsOpen.bind(this), false);
        ws.addEventListener("close", this.handleWsClose.bind(this), false);
        ws.addEventListener("error", this.handleWsError.bind(this), false);
        ws.addEventListener("message", this.handleWsMessage.bind(this), false); //介绍信息对策方法
    },
    handleWsOpen(e) {
        console.log('连接开启了....')
        this.handleSendMsg(store.state.emailLogin[0].userID)

    },
    handleWsClose(e) {
        console.log('ws关闭')
    },
    handleWsError(e) {
        console.log('ws错误')
    },
    handleWsMessage(e) {
        return e
    },
    //信息发送
    handleSendMsg(data) {

        ws.send(JSON.stringify(data))
    },
}
export default wsConnection